import pymysql
from superduper import superduper

# 将 pymysql 安装为 MySQLdb
pymysql.install_as_MySQLdb()

# 创建 superduper 数据库连接
db_uri = 'mysql://root:1026@localhost/superduper'
db = superduper(db_uri)

# 使用 pymysql 连接数据库
connection = pymysql.connect(host='localhost',
                             user='root',
                             password='1026',
                             database='superduper',
                             cursorclass=pymysql.cursors.DictCursor)

try:
    with connection.cursor() as cursor:
        # SQL 查询，用于获取表中的内容
        table_name = 'province_population'
        sql = f"SELECT * FROM `{table_name}`"
        cursor.execute(sql)
        
        # 获取查询结果
        result = cursor.fetchall()
        
        # 打印表内容
        print(f"Contents of {table_name} table:")
        for row in result:
            print(row)
finally:
    # 关闭数据库连接
    connection.close()
